
/**************************************************************************************
* [Project]
*       GamePk
* [Package]
*       com.bchun.gamepk.web.action
* [FileName]
*       ServicesAction.java
* [Copyright]
*       Copyright 2014 BCHUN All Rights Reserved.
* [History]
*       Version          Date              Author                        Record
*--------------------------------------------------------------------------------------
*       1.0.0           2014-2-27         luoxudong (hi@luoxudong.com)        Create
**************************************************************************************/
	
package com.bchun.gamepk.web.action;

import com.bchun.gamepk.service.IServicesService;
import com.bchun.gamepk.web.common.ResultCode;
import com.bchun.gamepk.web.common.ResultMessage;
import com.bchun.gamepk.web.common.ServiceFuncValue;
import com.bchun.gamepk.web.model.resposne.ServerResult;


/********************************************************************
 * [Summary]
 *       TODO 请在此处简要描述此类所实现的功能。因为这项注释主要是为了在IDE环境中生成tip帮助，务必简明扼要
 * [Remarks]
 *       TODO 请在此处详细描述类的功能、调用方法、注意事项、以及与其它类的关系.
 *******************************************************************/

public class ServicesAction extends BaseCommonAction{
	private static final long serialVersionUID = 1L;
	private IServicesService servicesService = null;

	public ServicesAction(IServicesService servicesService)
	{
		this.servicesService = servicesService;
	}
	
	
	@Override
	public String execute() {
		String funcStr = getRequest().getParameter("func");
		
		if (funcStr == null){//无效接口名称
			ServerResult result = new ServerResult();
			result.setResultCode(ResultCode.fail.getValue());
			result.setResultMessage(ResultMessage.funcNotExist.getValue());
			outJsonObject(result);
			return null;//ActionResult.success.getValue();
		} 
		
		String requestJson = getRequestData(getRequest());
		
		if (requestJson == null || "".equals(requestJson.trim()))
		{
			ServerResult result = new ServerResult();
			result.setResultCode(ResultCode.fail.getValue());
			result.setResultMessage(ResultMessage.requestParamError.getValue());
			outJsonObject(result);
			return null;
		}
		
		Object responseJsonObject = null;
		System.out.println("请求信息:[func=" + funcStr + "]>>>" + requestJson);
		
		if (funcStr.equalsIgnoreCase(ServiceFuncValue.reg.getValue())){//注册
			responseJsonObject = servicesService.reg(requestJson);
		}else if (funcStr.equalsIgnoreCase(ServiceFuncValue.login.getValue())){//登陆
			responseJsonObject = servicesService.login(requestJson);
		}else if (funcStr.equalsIgnoreCase(ServiceFuncValue.hotGames.getValue())){//获取热门游戏
				
		}else {
			ServerResult result = new ServerResult();
			result.setResultCode(ResultCode.fail.getValue());
			result.setResultMessage(ResultMessage.funcNotExist.getValue());
			responseJsonObject = result;
		}
		
		if (responseJsonObject == null)
		{
			ServerResult result = new ServerResult();
			result.setResultCode(ResultCode.fail.getValue());
			result.setResultMessage(ResultMessage.fail.getValue());
			responseJsonObject = result;
		}
		
		outJsonObject(responseJsonObject);
		return null;//ActionResult.success.getValue();
	}
}
